/*
 * Copyright (c) 2023 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#include "interface/network_adapter.h"

namespace dev {

bool NetworkAdapter::update_firmware_version_by_ncsi() {
    ncsi_version_id_info_t version_id = {};
    bool                   ret =
        m_ncsi_over_mctp_wx->get_version_id(DEFAULT_PACKAGE_ID, DEFAULT_CHANNEL_ID, &version_id);
    if (!ret) {
        elog("Error: Failed to update version id");
        return false;
    }
    FirmwareVersion.set_value(version_id.firmware_version);
    return true;
}

void NetworkAdapter::start_ncsi_update_task_wx(ncsi_over_mctp_wx_ptr ncsi_over_mctp,
                                               mc::milliseconds      interval) {
    m_ncsi_timer        = new mc::core::timer(this);
    m_ncsi_over_mctp_wx = ncsi_over_mctp;
    m_ncsi_timer->timeout.connect([this]() {
        update_firmware_version_by_ncsi();
    });
    m_ncsi_timer->set_single_shot(false);
    m_ncsi_timer->start(interval);
}

void NetworkAdapter::stop_ncsi_update_task() {
    m_ncsi_timer->stop();
}

void NetworkAdapter::HandleOsResetSignal() {
    // wx网卡的OS重置信号处理
    // 当前wx网卡不需要特殊的OS重置处理，保持空实现
}
} // namespace dev

MC_REFLECT(dev::NetworkAdapter)